<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class Update5 extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 商品表
        Schema::table('skus', function (Blueprint $table) {
            $table->boolean('cover_chip_status')->default(0)->index()->after('status')->comment('碎片兑换开关');
            $table->integer('cover_chip_id')->nullable()->index()->after('status')->comment('碎片ID');
            $table->integer('cover_chip_total')->nullable()->after('status')->comment('所需碎片数量');
            $table->integer('cover_chip_count')->default(0)->after('status')->comment('兑换次数');
        });

        // 商品表
        Schema::table('products', function (Blueprint $table) {
            $table->boolean('cover_chip_status')->default(0)->index()->after('status')->comment('碎片兑换开关');
        });

        // 商品表
        Schema::table('orders', function (Blueprint $table) {
            $table->integer('cover_discount')->nullable()->after('coupon_discount')->comment('兑换优惠抵扣');
            $table->string('cover_type', 20)->nullable()->index()->after('coupon_discount')->comment('兑换消耗资产的类型');
            $table->integer('cover_asset_id')->nullable()->index()->after('coupon_discount')->comment('兑换消耗资产的id');
            $table->integer('cover_asset_total')->nullable()->after('coupon_discount')->comment('兑换消耗资产数量');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('skus', function (Blueprint $table) {
            $table->dropColumn('cover_chip_status');
            $table->dropColumn('cover_chip_id');
            $table->dropColumn('cover_chip_total');
            $table->dropColumn('cover_chip_count');
        });

        Schema::table('products', function (Blueprint $table) {
            $table->dropColumn('cover_chip_status');
        });

        Schema::table('orders', function (Blueprint $table) {
            $table->dropColumn('cover_discount');
            $table->dropColumn('cover_type');
            $table->dropColumn('cover_asset_id');
            $table->dropColumn('cover_asset_total');
        });
    }
}
